// **************************************************************
// COPYRIGHT(c)2020, Xidian University
// All rights reserved.
//
// IP LIB INDEX :  
// IP Name      :      
// File name    : np_32ME_jtag_top.v
// Module name  : np_32ME_jtag_top
// Full name    :  
//
// Author       : lhb
// Email        : 2296971136@qq.com
// Data         : 2021/5/19
// Version      : V 1.0 
// 
// Abstract     : 32个ME的JTAG TAP控制器，主要用于识别每个核的ID
// Called by    : NP_top
// Note         : 32个ME以菊花链的形式连接，应保证trst、tck、tms信号的完整性，有足够的驱动能力。
// Modification history
// -----------------------------------------------------------------
// 
// 
// 
// *****************************************************************
`include "np_jtag_macros.v"

`timescale 1ns/10fs
module np_32ME_jtag_top(
    input  wire         cfg_clk,
    input  wire         cfg_rst,

    // JTAG interface    
    input  wire         jtag_trst,
    input  wire         jtag_tms,
    input  wire         jtag_tdi,
    output wire         jtag_tdo,
    output wire         jtag_tdo_en,
    input  wire         jtag_clk,
    input  wire         jtag_clk_n,

    // Scan Signals
    input  wire         scan_mode,
    input  wire         scan_set_rst,

    output wire [31:0]  cfg_addr_o         ,
    output wire [31:0]  cfg_wr_data_o      ,
    output wire         cfg_wr_en_o        ,
    output wire         cfg_rd_en_o        ,
    input  wire [31:0]  cfg_rd_data_i      ,

    output wire         jtag_occupy
);

//clk
// wire jtag_clk;
// wire jtag_clk_n;

wire jtag_tdi_ME0;
wire jtag_tdo_ME0;
wire jtag_tdi_ME1;
wire jtag_tdo_ME1;
wire jtag_tdi_ME2;
wire jtag_tdo_ME2;
wire jtag_tdi_ME3;
wire jtag_tdo_ME3;
wire jtag_tdi_ME4;
wire jtag_tdo_ME4;
wire jtag_tdi_ME5;
wire jtag_tdo_ME5;
wire jtag_tdi_ME6;
wire jtag_tdo_ME6;
wire jtag_tdi_ME7;
wire jtag_tdo_ME7;
wire jtag_tdi_ME8;
wire jtag_tdo_ME8;
wire jtag_tdi_ME9;
wire jtag_tdo_ME9;
wire jtag_tdi_ME10;
wire jtag_tdo_ME10;
wire jtag_tdi_ME11;
wire jtag_tdo_ME11;
wire jtag_tdi_ME12;
wire jtag_tdo_ME12;
wire jtag_tdi_ME13;
wire jtag_tdo_ME13;
wire jtag_tdi_ME14;
wire jtag_tdo_ME14;
wire jtag_tdi_ME15;
wire jtag_tdo_ME15;
wire jtag_tdi_ME16;
wire jtag_tdo_ME16;
wire jtag_tdi_ME17;
wire jtag_tdo_ME17;
wire jtag_tdi_ME18;
wire jtag_tdo_ME18;
wire jtag_tdi_ME19;
wire jtag_tdo_ME19;
wire jtag_tdi_ME20;
wire jtag_tdo_ME20;
wire jtag_tdi_ME21;
wire jtag_tdo_ME21;
wire jtag_tdi_ME22;
wire jtag_tdo_ME22;
wire jtag_tdi_ME23;
wire jtag_tdo_ME23;
wire jtag_tdi_ME24;
wire jtag_tdo_ME24;
wire jtag_tdi_ME25;
wire jtag_tdo_ME25;
wire jtag_tdi_ME26;
wire jtag_tdo_ME26;
wire jtag_tdi_ME27;
wire jtag_tdo_ME27;
wire jtag_tdi_ME28;
wire jtag_tdo_ME28;
wire jtag_tdi_ME29;
wire jtag_tdo_ME29;
wire jtag_tdi_ME30;
wire jtag_tdo_ME30;
wire jtag_tdi_ME31;
wire jtag_tdo_ME31;
wire jtag_tdo_en_ME0 ;
wire jtag_tdo_en_ME1 ;
wire jtag_tdo_en_ME2 ;
wire jtag_tdo_en_ME3 ;
wire jtag_tdo_en_ME4 ;
wire jtag_tdo_en_ME5 ;
wire jtag_tdo_en_ME6 ;
wire jtag_tdo_en_ME7 ;
wire jtag_tdo_en_ME8 ;
wire jtag_tdo_en_ME9 ;
wire jtag_tdo_en_ME10;
wire jtag_tdo_en_ME11;
wire jtag_tdo_en_ME12;
wire jtag_tdo_en_ME13;
wire jtag_tdo_en_ME14;
wire jtag_tdo_en_ME15;
wire jtag_tdo_en_ME16;
wire jtag_tdo_en_ME17;
wire jtag_tdo_en_ME18;
wire jtag_tdo_en_ME19;
wire jtag_tdo_en_ME20;
wire jtag_tdo_en_ME21;
wire jtag_tdo_en_ME22;
wire jtag_tdo_en_ME23;
wire jtag_tdo_en_ME24;
wire jtag_tdo_en_ME25;
wire jtag_tdo_en_ME26;
wire jtag_tdo_en_ME27;
wire jtag_tdo_en_ME28;
wire jtag_tdo_en_ME29;
wire jtag_tdo_en_ME30;
wire jtag_tdo_en_ME31;
// ---------------------------------------------------
// Generate jtag_clk, jtag_clk_n and cfg_ext_clk
// ---------------------------------------------------
// Create a positive and negative jtag clocks to deal with falling-edge flops
// assign jtag_clk = jtag_tck;
// assign jtag_clk_n = ~jtag_tck;

//ME0
np_jtag_top ME0_jtag_top (
    // Clocks and resets
    // .cfg_ext_clk        (cfg_ext_clk    ),
    // .cfg_ext_clk_rst    (cfg_ext_clk_rst),
    .cfg_clk            (cfg_clk    ),
    .cfg_rst            (cfg_rst    ),

    // JTAG interface    
    .jtag_trst          (jtag_trst  ),
    .jtag_tms           (jtag_tms   ),
    .jtag_tdi           (jtag_tdi_ME0   ),
    .jtag_tdo           (jtag_tdo_ME0   ),
    .jtag_tdo_en        (jtag_tdo_en_ME0),
    // .jtag_tck           (jtag_tck   ),
    .jtag_clk           (jtag_clk),
    .jtag_clk_n         (jtag_clk_n),
    // Scan Signals
    .scan_mode          (scan_mode   ),
    .scan_set_rst       (scan_set_rst),

    .cfg_addr_o         (cfg_addr_o   ),
    .cfg_wr_data_o      (cfg_wr_data_o),
    .cfg_wr_en_o        (cfg_wr_en_o  ),
    .cfg_rd_en_o        (cfg_rd_en_o  ),
    .cfg_rd_data_i      (cfg_rd_data_i),

    .jtag_occupy        (jtag_occupy)
);

//ME1
np_jtag_ctl_me1_31 #(.NP_JTAG_DR_IDCODE_VAL(`NP_JTAG_DR_IDCODE_VAL_ME1))
ME1_jtag_ctl (
    // TAP interface
    .jtag_trst          (jtag_trst),
    //input  wire         jtag_tck,
    .jtag_tms           (jtag_tms),
    .jtag_tdi           (jtag_tdi_ME1),
    .jtag_tdo           (jtag_tdo_ME1),
    .jtag_tdo_en        (jtag_tdo_en_ME1),

    // Scan interface
    .scan_mode          (scan_mode),
    .scan_set_rst       (scan_set_rst),

    // Generic JTAG register control signals
    .jtag_clk           (jtag_clk),
    .jtag_clk_n         (jtag_clk_n),
    //output  wire         jtag_clk,
    //output  wire         jtag_clk_n,
    .jtag_rst           (),
    .jtag_ser_in        (),
    .jtag_capture       (),
    .jtag_shift         (),
    .jtag_update        ()

    // Individual JTAG registers not contained herein
    //.jtag_cfg_sel       (),
    //.jtag_cfg_tdo       ()
);

//ME2
np_jtag_ctl_me1_31 #(.NP_JTAG_DR_IDCODE_VAL(`NP_JTAG_DR_IDCODE_VAL_ME2))
ME2_jtag_ctl (
    // TAP interface
    .jtag_trst          (jtag_trst),
    //input  wire         jtag_tck,
    .jtag_tms           (jtag_tms),
    .jtag_tdi           (jtag_tdi_ME2),
    .jtag_tdo           (jtag_tdo_ME2),
    .jtag_tdo_en        (jtag_tdo_en_ME2),

    // Scan interface
    .scan_mode          (scan_mode),
    .scan_set_rst       (scan_set_rst),

    // Generic JTAG register control signals
    .jtag_clk           (jtag_clk),
    .jtag_clk_n         (jtag_clk_n),
    //output  wire         jtag_clk,
    //output  wire         jtag_clk_n,
    .jtag_rst           (),
    .jtag_ser_in        (),
    .jtag_capture       (),
    .jtag_shift         (),
    .jtag_update        ()

    // Individual JTAG registers not contained herein
    //.jtag_cfg_sel       (),
    //.jtag_cfg_tdo       ()
);
//ME3
np_jtag_ctl_me1_31 #(.NP_JTAG_DR_IDCODE_VAL(`NP_JTAG_DR_IDCODE_VAL_ME3))
ME3_jtag_ctl (
    // TAP interface
    .jtag_trst          (jtag_trst),
    //input  wire         jtag_tck,
    .jtag_tms           (jtag_tms),
    .jtag_tdi           (jtag_tdi_ME3),
    .jtag_tdo           (jtag_tdo_ME3),
    .jtag_tdo_en        (jtag_tdo_en_ME3),

    // Scan interface
    .scan_mode          (scan_mode),
    .scan_set_rst       (scan_set_rst),

    // Generic JTAG register control signals
    .jtag_clk           (jtag_clk),
    .jtag_clk_n         (jtag_clk_n),
    //output  wire         jtag_clk,
    //output  wire         jtag_clk_n,
    .jtag_rst           (),
    .jtag_ser_in        (),
    .jtag_capture       (),
    .jtag_shift         (),
    .jtag_update        ()

    // Individual JTAG registers not contained herein
    //.jtag_cfg_sel       (),
    //.jtag_cfg_tdo       ()
);
//ME4
np_jtag_ctl_me1_31 #(.NP_JTAG_DR_IDCODE_VAL(`NP_JTAG_DR_IDCODE_VAL_ME4))
ME4_jtag_ctl (
    // TAP interface
    .jtag_trst          (jtag_trst),
    //input  wire         jtag_tck,
    .jtag_tms           (jtag_tms),
    .jtag_tdi           (jtag_tdi_ME4),
    .jtag_tdo           (jtag_tdo_ME4),
    .jtag_tdo_en        (jtag_tdo_en_ME4),

    // Scan interface
    .scan_mode          (scan_mode),
    .scan_set_rst       (scan_set_rst),

    // Generic JTAG register control signals
    .jtag_clk           (jtag_clk),
    .jtag_clk_n         (jtag_clk_n),
    //output  wire         jtag_clk,
    //output  wire         jtag_clk_n,
    .jtag_rst           (),
    .jtag_ser_in        (),
    .jtag_capture       (),
    .jtag_shift         (),
    .jtag_update        ()

    // Individual JTAG registers not contained herein
    //.jtag_cfg_sel       (),
    //.jtag_cfg_tdo       ()
);
//ME5
np_jtag_ctl_me1_31 #(.NP_JTAG_DR_IDCODE_VAL(`NP_JTAG_DR_IDCODE_VAL_ME5))
ME5_jtag_ctl (
    // TAP interface
    .jtag_trst          (jtag_trst),
    //input  wire         jtag_tck,
    .jtag_tms           (jtag_tms),
    .jtag_tdi           (jtag_tdi_ME5),
    .jtag_tdo           (jtag_tdo_ME5),
    .jtag_tdo_en        (jtag_tdo_en_ME5),

    // Scan interface
    .scan_mode          (scan_mode),
    .scan_set_rst       (scan_set_rst),

    // Generic JTAG register control signals
    .jtag_clk           (jtag_clk),
    .jtag_clk_n         (jtag_clk_n),
    //output  wire         jtag_clk,
    //output  wire         jtag_clk_n,
    .jtag_rst           (),
    .jtag_ser_in        (),
    .jtag_capture       (),
    .jtag_shift         (),
    .jtag_update        ()

    // Individual JTAG registers not contained herein
    //.jtag_cfg_sel       (),
    //.jtag_cfg_tdo       ()
);
//ME6
np_jtag_ctl_me1_31 #(.NP_JTAG_DR_IDCODE_VAL(`NP_JTAG_DR_IDCODE_VAL_ME6))
ME6_jtag_ctl (
    // TAP interface
    .jtag_trst          (jtag_trst),
    //input  wire         jtag_tck,
    .jtag_tms           (jtag_tms),
    .jtag_tdi           (jtag_tdi_ME6),
    .jtag_tdo           (jtag_tdo_ME6),
    .jtag_tdo_en        (jtag_tdo_en_ME6),

    // Scan interface
    .scan_mode          (scan_mode),
    .scan_set_rst       (scan_set_rst),

    // Generic JTAG register control signals
    .jtag_clk           (jtag_clk),
    .jtag_clk_n         (jtag_clk_n),
    //output  wire         jtag_clk,
    //output  wire         jtag_clk_n,
    .jtag_rst           (),
    .jtag_ser_in        (),
    .jtag_capture       (),
    .jtag_shift         (),
    .jtag_update        ()

    // Individual JTAG registers not contained herein
    //.jtag_cfg_sel       (),
    //.jtag_cfg_tdo       ()
);
//ME7
np_jtag_ctl_me1_31 #(.NP_JTAG_DR_IDCODE_VAL(`NP_JTAG_DR_IDCODE_VAL_ME7))
ME7_jtag_ctl (
    // TAP interface
    .jtag_trst          (jtag_trst),
    //input  wire         jtag_tck,
    .jtag_tms           (jtag_tms),
    .jtag_tdi           (jtag_tdi_ME7),
    .jtag_tdo           (jtag_tdo_ME7),
    .jtag_tdo_en        (jtag_tdo_en_ME7),

    // Scan interface
    .scan_mode          (scan_mode),
    .scan_set_rst       (scan_set_rst),

    // Generic JTAG register control signals
    .jtag_clk           (jtag_clk),
    .jtag_clk_n         (jtag_clk_n),
    //output  wire         jtag_clk,
    //output  wire         jtag_clk_n,
    .jtag_rst           (),
    .jtag_ser_in        (),
    .jtag_capture       (),
    .jtag_shift         (),
    .jtag_update        ()

    // Individual JTAG registers not contained herein
    //.jtag_cfg_sel       (),
    //.jtag_cfg_tdo       ()
);
//ME8
np_jtag_ctl_me1_31 #(.NP_JTAG_DR_IDCODE_VAL(`NP_JTAG_DR_IDCODE_VAL_ME8))
ME8_jtag_ctl (
    // TAP interface
    .jtag_trst          (jtag_trst),
    //input  wire         jtag_tck,
    .jtag_tms           (jtag_tms),
    .jtag_tdi           (jtag_tdi_ME8),
    .jtag_tdo           (jtag_tdo_ME8),
    .jtag_tdo_en        (jtag_tdo_en_ME8),

    // Scan interface
    .scan_mode          (scan_mode),
    .scan_set_rst       (scan_set_rst),

    // Generic JTAG register control signals
    .jtag_clk           (jtag_clk),
    .jtag_clk_n         (jtag_clk_n),
    //output  wire         jtag_clk,
    //output  wire         jtag_clk_n,
    .jtag_rst           (),
    .jtag_ser_in        (),
    .jtag_capture       (),
    .jtag_shift         (),
    .jtag_update        ()

    // Individual JTAG registers not contained herein
    //.jtag_cfg_sel       (),
    //.jtag_cfg_tdo       ()
);
//ME9
np_jtag_ctl_me1_31 #(.NP_JTAG_DR_IDCODE_VAL(`NP_JTAG_DR_IDCODE_VAL_ME9))
ME9_jtag_ctl (
    // TAP interface
    .jtag_trst          (jtag_trst),
    //input  wire         jtag_tck,
    .jtag_tms           (jtag_tms),
    .jtag_tdi           (jtag_tdi_ME9),
    .jtag_tdo           (jtag_tdo_ME9),
    .jtag_tdo_en        (jtag_tdo_en_ME9),

    // Scan interface
    .scan_mode          (scan_mode),
    .scan_set_rst       (scan_set_rst),

    // Generic JTAG register control signals
    .jtag_clk           (jtag_clk),
    .jtag_clk_n         (jtag_clk_n),
    //output  wire         jtag_clk,
    //output  wire         jtag_clk_n,
    .jtag_rst           (),
    .jtag_ser_in        (),
    .jtag_capture       (),
    .jtag_shift         (),
    .jtag_update        ()

    // Individual JTAG registers not contained herein
    //.jtag_cfg_sel       (),
    //.jtag_cfg_tdo       ()
);
//ME10
np_jtag_ctl_me1_31 #(.NP_JTAG_DR_IDCODE_VAL(`NP_JTAG_DR_IDCODE_VAL_ME10))
ME10_jtag_ctl (
    // TAP interface
    .jtag_trst          (jtag_trst),
    //input  wire         jtag_tck,
    .jtag_tms           (jtag_tms),
    .jtag_tdi           (jtag_tdi_ME10),
    .jtag_tdo           (jtag_tdo_ME10),
    .jtag_tdo_en        (jtag_tdo_en_ME10),

    // Scan interface
    .scan_mode          (scan_mode),
    .scan_set_rst       (scan_set_rst),

    // Generic JTAG register control signals
    .jtag_clk           (jtag_clk),
    .jtag_clk_n         (jtag_clk_n),
    //output  wire         jtag_clk,
    //output  wire         jtag_clk_n,
    .jtag_rst           (),
    .jtag_ser_in        (),
    .jtag_capture       (),
    .jtag_shift         (),
    .jtag_update        ()

    // Individual JTAG registers not contained herein
    //.jtag_cfg_sel       (),
    //.jtag_cfg_tdo       ()
);
//ME11
np_jtag_ctl_me1_31 #(.NP_JTAG_DR_IDCODE_VAL(`NP_JTAG_DR_IDCODE_VAL_ME11))
ME11_jtag_ctl (
    // TAP interface
    .jtag_trst          (jtag_trst),
    //input  wire         jtag_tck,
    .jtag_tms           (jtag_tms),
    .jtag_tdi           (jtag_tdi_ME11),
    .jtag_tdo           (jtag_tdo_ME11),
    .jtag_tdo_en        (jtag_tdo_en_ME11),

    // Scan interface
    .scan_mode          (scan_mode),
    .scan_set_rst       (scan_set_rst),

    // Generic JTAG register control signals
    .jtag_clk           (jtag_clk),
    .jtag_clk_n         (jtag_clk_n),
    //output  wire         jtag_clk,
    //output  wire         jtag_clk_n,
    .jtag_rst           (),
    .jtag_ser_in        (),
    .jtag_capture       (),
    .jtag_shift         (),
    .jtag_update        ()

    // Individual JTAG registers not contained herein
    //.jtag_cfg_sel       (),
    //.jtag_cfg_tdo       ()
);
//ME12
np_jtag_ctl_me1_31 #(.NP_JTAG_DR_IDCODE_VAL(`NP_JTAG_DR_IDCODE_VAL_ME12))
ME12_jtag_ctl (
    // TAP interface
    .jtag_trst          (jtag_trst),
    //input  wire         jtag_tck,
    .jtag_tms           (jtag_tms),
    .jtag_tdi           (jtag_tdi_ME12),
    .jtag_tdo           (jtag_tdo_ME12),
    .jtag_tdo_en        (jtag_tdo_en_ME12),

    // Scan interface
    .scan_mode          (scan_mode),
    .scan_set_rst       (scan_set_rst),

    // Generic JTAG register control signals
    .jtag_clk           (jtag_clk),
    .jtag_clk_n         (jtag_clk_n),
    //output  wire         jtag_clk,
    //output  wire         jtag_clk_n,
    .jtag_rst           (),
    .jtag_ser_in        (),
    .jtag_capture       (),
    .jtag_shift         (),
    .jtag_update        ()

    // Individual JTAG registers not contained herein
    //.jtag_cfg_sel       (),
    //.jtag_cfg_tdo       ()
);
//ME13
np_jtag_ctl_me1_31 #(.NP_JTAG_DR_IDCODE_VAL(`NP_JTAG_DR_IDCODE_VAL_ME13))
ME13_jtag_ctl (
    // TAP interface
    .jtag_trst          (jtag_trst),
    //input  wire         jtag_tck,
    .jtag_tms           (jtag_tms),
    .jtag_tdi           (jtag_tdi_ME13),
    .jtag_tdo           (jtag_tdo_ME13),
    .jtag_tdo_en        (jtag_tdo_en_ME13),

    // Scan interface
    .scan_mode          (scan_mode),
    .scan_set_rst       (scan_set_rst),

    // Generic JTAG register control signals
    .jtag_clk           (jtag_clk),
    .jtag_clk_n         (jtag_clk_n),
    //output  wire         jtag_clk,
    //output  wire         jtag_clk_n,
    .jtag_rst           (),
    .jtag_ser_in        (),
    .jtag_capture       (),
    .jtag_shift         (),
    .jtag_update        ()

    // Individual JTAG registers not contained herein
    //.jtag_cfg_sel       (),
    //.jtag_cfg_tdo       ()
);
//ME14
np_jtag_ctl_me1_31 #(.NP_JTAG_DR_IDCODE_VAL(`NP_JTAG_DR_IDCODE_VAL_ME14))
ME14_jtag_ctl (
    // TAP interface
    .jtag_trst          (jtag_trst),
    //input  wire         jtag_tck,
    .jtag_tms           (jtag_tms),
    .jtag_tdi           (jtag_tdi_ME14),
    .jtag_tdo           (jtag_tdo_ME14),
    .jtag_tdo_en        (jtag_tdo_en_ME14),

    // Scan interface
    .scan_mode          (scan_mode),
    .scan_set_rst       (scan_set_rst),

    // Generic JTAG register control signals
    .jtag_clk           (jtag_clk),
    .jtag_clk_n         (jtag_clk_n),
    //output  wire         jtag_clk,
    //output  wire         jtag_clk_n,
    .jtag_rst           (),
    .jtag_ser_in        (),
    .jtag_capture       (),
    .jtag_shift         (),
    .jtag_update        ()

    // Individual JTAG registers not contained herein
    //.jtag_cfg_sel       (),
    //.jtag_cfg_tdo       ()
);
//ME15
np_jtag_ctl_me1_31 #(.NP_JTAG_DR_IDCODE_VAL(`NP_JTAG_DR_IDCODE_VAL_ME15))
ME15_jtag_ctl (
    // TAP interface
    .jtag_trst          (jtag_trst),
    //input  wire         jtag_tck,
    .jtag_tms           (jtag_tms),
    .jtag_tdi           (jtag_tdi_ME15),
    .jtag_tdo           (jtag_tdo_ME15),
    .jtag_tdo_en        (jtag_tdo_en_ME15),

    // Scan interface
    .scan_mode          (scan_mode),
    .scan_set_rst       (scan_set_rst),

    // Generic JTAG register control signals
    .jtag_clk           (jtag_clk),
    .jtag_clk_n         (jtag_clk_n),
    //output  wire         jtag_clk,
    //output  wire         jtag_clk_n,
    .jtag_rst           (),
    .jtag_ser_in        (),
    .jtag_capture       (),
    .jtag_shift         (),
    .jtag_update        ()

    // Individual JTAG registers not contained herein
    //.jtag_cfg_sel       (),
    //.jtag_cfg_tdo       ()
);
//ME16
np_jtag_ctl_me1_31 #(.NP_JTAG_DR_IDCODE_VAL(`NP_JTAG_DR_IDCODE_VAL_ME16))
ME16_jtag_ctl (
    // TAP interface
    .jtag_trst          (jtag_trst),
    //input  wire         jtag_tck,
    .jtag_tms           (jtag_tms),
    .jtag_tdi           (jtag_tdi_ME16),
    .jtag_tdo           (jtag_tdo_ME16),
    .jtag_tdo_en        (jtag_tdo_en_ME16),

    // Scan interface
    .scan_mode          (scan_mode),
    .scan_set_rst       (scan_set_rst),

    // Generic JTAG register control signals
    .jtag_clk           (jtag_clk),
    .jtag_clk_n         (jtag_clk_n),
    //output  wire         jtag_clk,
    //output  wire         jtag_clk_n,
    .jtag_rst           (),
    .jtag_ser_in        (),
    .jtag_capture       (),
    .jtag_shift         (),
    .jtag_update        ()

    // Individual JTAG registers not contained herein
    //.jtag_cfg_sel       (),
    //.jtag_cfg_tdo       ()
);
//ME17
np_jtag_ctl_me1_31 #(.NP_JTAG_DR_IDCODE_VAL(`NP_JTAG_DR_IDCODE_VAL_ME17))
ME17_jtag_ctl (
    // TAP interface
    .jtag_trst          (jtag_trst),
    //input  wire         jtag_tck,
    .jtag_tms           (jtag_tms),
    .jtag_tdi           (jtag_tdi_ME17),
    .jtag_tdo           (jtag_tdo_ME17),
    .jtag_tdo_en        (jtag_tdo_en_ME17),

    // Scan interface
    .scan_mode          (scan_mode),
    .scan_set_rst       (1'b0),

    // Generic JTAG register control signals
    .jtag_clk           (jtag_clk),
    .jtag_clk_n         (jtag_clk_n),
    //output  wire         jtag_clk,
    //output  wire         jtag_clk_n,
    .jtag_rst           (),
    .jtag_ser_in        (),
    .jtag_capture       (),
    .jtag_shift         (),
    .jtag_update        ()

    // Individual JTAG registers not contained herein
    //.jtag_cfg_sel       (),
    //.jtag_cfg_tdo       ()
);
//ME18
np_jtag_ctl_me1_31 #(.NP_JTAG_DR_IDCODE_VAL(`NP_JTAG_DR_IDCODE_VAL_ME18))
ME18_jtag_ctl (
    // TAP interface
    .jtag_trst          (jtag_trst),
    //input  wire         jtag_tck,
    .jtag_tms           (jtag_tms),
    .jtag_tdi           (jtag_tdi_ME18),
    .jtag_tdo           (jtag_tdo_ME18),
    .jtag_tdo_en        (jtag_tdo_en_ME18),

    // Scan interface
    .scan_mode          (scan_mode),
    .scan_set_rst       (scan_set_rst),

    // Generic JTAG register control signals
    .jtag_clk           (jtag_clk),
    .jtag_clk_n         (jtag_clk_n),
    //output  wire         jtag_clk,
    //output  wire         jtag_clk_n,
    .jtag_rst           (),
    .jtag_ser_in        (),
    .jtag_capture       (),
    .jtag_shift         (),
    .jtag_update        ()

    // Individual JTAG registers not contained herein
    //.jtag_cfg_sel       (),
    //.jtag_cfg_tdo       ()
);
//ME19
np_jtag_ctl_me1_31 #(.NP_JTAG_DR_IDCODE_VAL(`NP_JTAG_DR_IDCODE_VAL_ME19))
ME19_jtag_ctl (
    // TAP interface
    .jtag_trst          (jtag_trst),
    //input  wire         jtag_tck,
    .jtag_tms           (jtag_tms),
    .jtag_tdi           (jtag_tdi_ME19),
    .jtag_tdo           (jtag_tdo_ME19),
    .jtag_tdo_en        (jtag_tdo_en_ME19),

    // Scan interface
    .scan_mode          (scan_mode),
    .scan_set_rst       (scan_set_rst),

    // Generic JTAG register control signals
    .jtag_clk           (jtag_clk),
    .jtag_clk_n         (jtag_clk_n),
    //output  wire         jtag_clk,
    //output  wire         jtag_clk_n,
    .jtag_rst           (),
    .jtag_ser_in        (),
    .jtag_capture       (),
    .jtag_shift         (),
    .jtag_update        ()

    // Individual JTAG registers not contained herein
    //.jtag_cfg_sel       (),
    //.jtag_cfg_tdo       ()
);
//ME20
np_jtag_ctl_me1_31 #(.NP_JTAG_DR_IDCODE_VAL(`NP_JTAG_DR_IDCODE_VAL_ME20))
ME20_jtag_ctl (
    // TAP interface
    .jtag_trst          (jtag_trst),
    //input  wire         jtag_tck,
    .jtag_tms           (jtag_tms),
    .jtag_tdi           (jtag_tdi_ME20),
    .jtag_tdo           (jtag_tdo_ME20),
    .jtag_tdo_en        (jtag_tdo_en_ME20),

    // Scan interface
    .scan_mode          (scan_mode),
    .scan_set_rst       (scan_set_rst),

    // Generic JTAG register control signals
    .jtag_clk           (jtag_clk),
    .jtag_clk_n         (jtag_clk_n),
    //output  wire         jtag_clk,
    //output  wire         jtag_clk_n,
    .jtag_rst           (),
    .jtag_ser_in        (),
    .jtag_capture       (),
    .jtag_shift         (),
    .jtag_update        ()

    // Individual JTAG registers not contained herein
    //.jtag_cfg_sel       (),
    //.jtag_cfg_tdo       ()
);
//ME21
np_jtag_ctl_me1_31 #(.NP_JTAG_DR_IDCODE_VAL(`NP_JTAG_DR_IDCODE_VAL_ME21))
ME21_jtag_ctl (
    // TAP interface
    .jtag_trst          (jtag_trst),
    //input  wire         jtag_tck,
    .jtag_tms           (jtag_tms),
    .jtag_tdi           (jtag_tdi_ME21),
    .jtag_tdo           (jtag_tdo_ME21),
    .jtag_tdo_en        (jtag_tdo_en_ME21),

    // Scan interface
    .scan_mode          (scan_mode),
    .scan_set_rst       (scan_set_rst),

    // Generic JTAG register control signals
    .jtag_clk           (jtag_clk),
    .jtag_clk_n         (jtag_clk_n),
    //output  wire         jtag_clk,
    //output  wire         jtag_clk_n,
    .jtag_rst           (),
    .jtag_ser_in        (),
    .jtag_capture       (),
    .jtag_shift         (),
    .jtag_update        ()

    // Individual JTAG registers not contained herein
    //.jtag_cfg_sel       (),
    //.jtag_cfg_tdo       ()
);
//ME22
np_jtag_ctl_me1_31 #(.NP_JTAG_DR_IDCODE_VAL(`NP_JTAG_DR_IDCODE_VAL_ME22))
ME22_jtag_ctl (
    // TAP interface
    .jtag_trst          (jtag_trst),
    //input  wire         jtag_tck,
    .jtag_tms           (jtag_tms),
    .jtag_tdi           (jtag_tdi_ME22),
    .jtag_tdo           (jtag_tdo_ME22),
    .jtag_tdo_en        (jtag_tdo_en_ME22),

    // Scan interface
    .scan_mode          (scan_mode),
    .scan_set_rst       (scan_set_rst),

    // Generic JTAG register control signals
    .jtag_clk           (jtag_clk),
    .jtag_clk_n         (jtag_clk_n),
    //output  wire         jtag_clk,
    //output  wire         jtag_clk_n,
    .jtag_rst           (),
    .jtag_ser_in        (),
    .jtag_capture       (),
    .jtag_shift         (),
    .jtag_update        ()

    // Individual JTAG registers not contained herein
    //.jtag_cfg_sel       (),
    //.jtag_cfg_tdo       ()
);
//ME23
np_jtag_ctl_me1_31 #(.NP_JTAG_DR_IDCODE_VAL(`NP_JTAG_DR_IDCODE_VAL_ME23))
ME23_jtag_ctl (
    // TAP interface
    .jtag_trst          (jtag_trst),
    //input  wire         jtag_tck,
    .jtag_tms           (jtag_tms),
    .jtag_tdi           (jtag_tdi_ME23),
    .jtag_tdo           (jtag_tdo_ME23),
    .jtag_tdo_en        (jtag_tdo_en_ME23),

    // Scan interface
    .scan_mode          (scan_mode),
    .scan_set_rst       (scan_set_rst),

    // Generic JTAG register control signals
    .jtag_clk           (jtag_clk),
    .jtag_clk_n         (jtag_clk_n),
    //output  wire         jtag_clk,
    //output  wire         jtag_clk_n,
    .jtag_rst           (),
    .jtag_ser_in        (),
    .jtag_capture       (),
    .jtag_shift         (),
    .jtag_update        ()

    // Individual JTAG registers not contained herein
    //.jtag_cfg_sel       (),
    //.jtag_cfg_tdo       ()
);
//ME24
np_jtag_ctl_me1_31 #(.NP_JTAG_DR_IDCODE_VAL(`NP_JTAG_DR_IDCODE_VAL_ME24))
ME24_jtag_ctl (
    // TAP interface
    .jtag_trst          (jtag_trst),
    //input  wire         jtag_tck,
    .jtag_tms           (jtag_tms),
    .jtag_tdi           (jtag_tdi_ME24),
    .jtag_tdo           (jtag_tdo_ME24),
    .jtag_tdo_en        (jtag_tdo_en_ME24),

    // Scan interface
    .scan_mode          (scan_mode),
    .scan_set_rst       (scan_set_rst),

    // Generic JTAG register control signals
    .jtag_clk           (jtag_clk),
    .jtag_clk_n         (jtag_clk_n),
    //output  wire         jtag_clk,
    //output  wire         jtag_clk_n,
    .jtag_rst           (),
    .jtag_ser_in        (),
    .jtag_capture       (),
    .jtag_shift         (),
    .jtag_update        ()

    // Individual JTAG registers not contained herein
    //.jtag_cfg_sel       (),
    //.jtag_cfg_tdo       ()
);
//ME25
np_jtag_ctl_me1_31 #(.NP_JTAG_DR_IDCODE_VAL(`NP_JTAG_DR_IDCODE_VAL_ME25))
ME25_jtag_ctl (
    // TAP interface
    .jtag_trst          (jtag_trst),
    //input  wire         jtag_tck,
    .jtag_tms           (jtag_tms),
    .jtag_tdi           (jtag_tdi_ME25),
    .jtag_tdo           (jtag_tdo_ME25),
    .jtag_tdo_en        (jtag_tdo_en_ME25),

    // Scan interface
    .scan_mode          (scan_mode),
    .scan_set_rst       (scan_set_rst),

    // Generic JTAG register control signals
    .jtag_clk           (jtag_clk),
    .jtag_clk_n         (jtag_clk_n),
    //output  wire         jtag_clk,
    //output  wire         jtag_clk_n,
    .jtag_rst           (),
    .jtag_ser_in        (),
    .jtag_capture       (),
    .jtag_shift         (),
    .jtag_update        ()

    // Individual JTAG registers not contained herein
    //.jtag_cfg_sel       (),
    //.jtag_cfg_tdo       ()
);
//ME26
np_jtag_ctl_me1_31 #(.NP_JTAG_DR_IDCODE_VAL(`NP_JTAG_DR_IDCODE_VAL_ME26))
ME26_jtag_ctl (
    // TAP interface
    .jtag_trst          (jtag_trst),
    //input  wire         jtag_tck,
    .jtag_tms           (jtag_tms),
    .jtag_tdi           (jtag_tdi_ME26),
    .jtag_tdo           (jtag_tdo_ME26),
    .jtag_tdo_en        (jtag_tdo_en_ME26),

    // Scan interface
    .scan_mode          (scan_mode),
    .scan_set_rst       (scan_set_rst),

    // Generic JTAG register control signals
    .jtag_clk           (jtag_clk),
    .jtag_clk_n         (jtag_clk_n),
    //output  wire         jtag_clk,
    //output  wire         jtag_clk_n,
    .jtag_rst           (),
    .jtag_ser_in        (),
    .jtag_capture       (),
    .jtag_shift         (),
    .jtag_update        ()

    // Individual JTAG registers not contained herein
    //.jtag_cfg_sel       (),
    //.jtag_cfg_tdo       ()
);
//ME27
np_jtag_ctl_me1_31 #(.NP_JTAG_DR_IDCODE_VAL(`NP_JTAG_DR_IDCODE_VAL_ME27))
ME27_jtag_ctl (
    // TAP interface
    .jtag_trst          (jtag_trst),
    //input  wire         jtag_tck,
    .jtag_tms           (jtag_tms),
    .jtag_tdi           (jtag_tdi_ME27),
    .jtag_tdo           (jtag_tdo_ME27),
    .jtag_tdo_en        (jtag_tdo_en_ME27),

    // Scan interface
    .scan_mode          (scan_mode),
    .scan_set_rst       (scan_set_rst),

    // Generic JTAG register control signals
    .jtag_clk           (jtag_clk),
    .jtag_clk_n         (jtag_clk_n),
    //output  wire         jtag_clk,
    //output  wire         jtag_clk_n,
    .jtag_rst           (),
    .jtag_ser_in        (),
    .jtag_capture       (),
    .jtag_shift         (),
    .jtag_update        ()

    // Individual JTAG registers not contained herein
    //.jtag_cfg_sel       (),
    //.jtag_cfg_tdo       ()
);
//ME28
np_jtag_ctl_me1_31 #(.NP_JTAG_DR_IDCODE_VAL(`NP_JTAG_DR_IDCODE_VAL_ME28))
ME28_jtag_ctl (
    // TAP interface
    .jtag_trst          (jtag_trst),
    //input  wire         jtag_tck,
    .jtag_tms           (jtag_tms),
    .jtag_tdi           (jtag_tdi_ME28),
    .jtag_tdo           (jtag_tdo_ME28),
    .jtag_tdo_en        (jtag_tdo_en_ME28),

    // Scan interface
    .scan_mode          (scan_mode),
    .scan_set_rst       (scan_set_rst),

    // Generic JTAG register control signals
    .jtag_clk           (jtag_clk),
    .jtag_clk_n         (jtag_clk_n),
    //output  wire         jtag_clk,
    //output  wire         jtag_clk_n,
    .jtag_rst           (),
    .jtag_ser_in        (),
    .jtag_capture       (),
    .jtag_shift         (),
    .jtag_update        ()

    // Individual JTAG registers not contained herein
    //.jtag_cfg_sel       (),
    //.jtag_cfg_tdo       ()
);
//ME29
np_jtag_ctl_me1_31 #(.NP_JTAG_DR_IDCODE_VAL(`NP_JTAG_DR_IDCODE_VAL_ME29))
ME29_jtag_ctl (
    // TAP interface
    .jtag_trst          (jtag_trst),
    //input  wire         jtag_tck,
    .jtag_tms           (jtag_tms),
    .jtag_tdi           (jtag_tdi_ME29),
    .jtag_tdo           (jtag_tdo_ME29),
    .jtag_tdo_en        (jtag_tdo_en_ME29),

    // Scan interface
    .scan_mode          (scan_mode),
    .scan_set_rst       (scan_set_rst),

    // Generic JTAG register control signals
    .jtag_clk           (jtag_clk),
    .jtag_clk_n         (jtag_clk_n),
    //output  wire         jtag_clk,
    //output  wire         jtag_clk_n,
    .jtag_rst           (),
    .jtag_ser_in        (),
    .jtag_capture       (),
    .jtag_shift         (),
    .jtag_update        ()

    // Individual JTAG registers not contained herein
    //.jtag_cfg_sel       (),
    //.jtag_cfg_tdo       ()
);
//ME30
np_jtag_ctl_me1_31 #(.NP_JTAG_DR_IDCODE_VAL(`NP_JTAG_DR_IDCODE_VAL_ME30))
ME30_jtag_ctl (
    // TAP interface
    .jtag_trst          (jtag_trst),
    //input  wire         jtag_tck,
    .jtag_tms           (jtag_tms),
    .jtag_tdi           (jtag_tdi_ME30),
    .jtag_tdo           (jtag_tdo_ME30),
    .jtag_tdo_en        (jtag_tdo_en_ME30),

    // Scan interface
    .scan_mode          (scan_mode),
    .scan_set_rst       (scan_set_rst),

    // Generic JTAG register control signals
    .jtag_clk           (jtag_clk),
    .jtag_clk_n         (jtag_clk_n),
    //output  wire         jtag_clk,
    //output  wire         jtag_clk_n,
    .jtag_rst           (),
    .jtag_ser_in        (),
    .jtag_capture       (),
    .jtag_shift         (),
    .jtag_update        ()

    // Individual JTAG registers not contained herein
    //.jtag_cfg_sel       (),
    //.jtag_cfg_tdo       ()
);
//ME31
np_jtag_ctl_me1_31 #(.NP_JTAG_DR_IDCODE_VAL(`NP_JTAG_DR_IDCODE_VAL_ME31))
ME31_jtag_ctl (
    // TAP interface
    .jtag_trst          (jtag_trst),
    //input  wire         jtag_tck,
    .jtag_tms           (jtag_tms),
    .jtag_tdi           (jtag_tdi_ME31),
    .jtag_tdo           (jtag_tdo_ME31),
    .jtag_tdo_en        (jtag_tdo_en_ME31),

    // Scan interface
    .scan_mode          (scan_mode),
    .scan_set_rst       (scan_set_rst),

    // Generic JTAG register control signals
    .jtag_clk           (jtag_clk),
    .jtag_clk_n         (jtag_clk_n),
    //output  wire         jtag_clk,
    //output  wire         jtag_clk_n,
    .jtag_rst           (),
    .jtag_ser_in        (),
    .jtag_capture       (),
    .jtag_shift         (),
    .jtag_update        ()

    // Individual JTAG registers not contained herein
    //.jtag_cfg_sel       (),
    //.jtag_cfg_tdo       ()
);
//TAP首尾相连
assign jtag_tdi_ME0 = jtag_tdi;
assign jtag_tdi_ME1  = jtag_tdo_ME0  && jtag_tdo_en_ME0 ;
assign jtag_tdi_ME2  = jtag_tdo_ME1  && jtag_tdo_en_ME1 ;
assign jtag_tdi_ME3  = jtag_tdo_ME2  && jtag_tdo_en_ME2 ;
assign jtag_tdi_ME4  = jtag_tdo_ME3  && jtag_tdo_en_ME3 ;
assign jtag_tdi_ME5  = jtag_tdo_ME4  && jtag_tdo_en_ME4 ;
assign jtag_tdi_ME6  = jtag_tdo_ME5  && jtag_tdo_en_ME5 ;
assign jtag_tdi_ME7  = jtag_tdo_ME6  && jtag_tdo_en_ME6 ;
assign jtag_tdi_ME8  = jtag_tdo_ME7  && jtag_tdo_en_ME7 ;
assign jtag_tdi_ME9  = jtag_tdo_ME8  && jtag_tdo_en_ME8 ;
assign jtag_tdi_ME10 = jtag_tdo_ME9  && jtag_tdo_en_ME9 ;
assign jtag_tdi_ME11 = jtag_tdo_ME10 && jtag_tdo_en_ME10;
assign jtag_tdi_ME12 = jtag_tdo_ME11 && jtag_tdo_en_ME11;
assign jtag_tdi_ME13 = jtag_tdo_ME12 && jtag_tdo_en_ME12;
assign jtag_tdi_ME14 = jtag_tdo_ME13 && jtag_tdo_en_ME13;
assign jtag_tdi_ME15 = jtag_tdo_ME14 && jtag_tdo_en_ME14;
assign jtag_tdi_ME16 = jtag_tdo_ME15 && jtag_tdo_en_ME15;
assign jtag_tdi_ME17 = jtag_tdo_ME16 && jtag_tdo_en_ME16;
assign jtag_tdi_ME18 = jtag_tdo_ME17 && jtag_tdo_en_ME17;
assign jtag_tdi_ME19 = jtag_tdo_ME18 && jtag_tdo_en_ME18;
assign jtag_tdi_ME20 = jtag_tdo_ME19 && jtag_tdo_en_ME19;
assign jtag_tdi_ME21 = jtag_tdo_ME20 && jtag_tdo_en_ME20;
assign jtag_tdi_ME22 = jtag_tdo_ME21 && jtag_tdo_en_ME21;
assign jtag_tdi_ME23 = jtag_tdo_ME22 && jtag_tdo_en_ME22;
assign jtag_tdi_ME24 = jtag_tdo_ME23 && jtag_tdo_en_ME23;
assign jtag_tdi_ME25 = jtag_tdo_ME24 && jtag_tdo_en_ME24;
assign jtag_tdi_ME26 = jtag_tdo_ME25 && jtag_tdo_en_ME25;
assign jtag_tdi_ME27 = jtag_tdo_ME26 && jtag_tdo_en_ME26;
assign jtag_tdi_ME28 = jtag_tdo_ME27 && jtag_tdo_en_ME27;
assign jtag_tdi_ME29 = jtag_tdo_ME28 && jtag_tdo_en_ME28;
assign jtag_tdi_ME30 = jtag_tdo_ME29 && jtag_tdo_en_ME29;
assign jtag_tdi_ME31 = jtag_tdo_ME30 && jtag_tdo_en_ME30;
assign jtag_tdo      = jtag_tdo_ME31 ;
assign jtag_tdo_en   = jtag_tdo_en_ME31;

endmodule
